{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e22001ca-c299-4676-ab0d-210620db4dd8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c076e877-45e3-45e6-8f5c-7b74da70cebf",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1=np.arange(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "80a29234-54a0-415b-a8f5-76f6611090ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9438b6e9-7585-4f50-bdc5-598d53cea1ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8]), array([ 9, 10, 11])]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.split(arr1,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8d7afafd-550f-4a62-b8bd-7fcd133edde4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([0, 1, 2]), array([3, 4]), array([ 5,  6,  7,  8,  9, 10, 11])]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.split(arr1,[3,5])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76e1a517-873d-48f7-961b-5d99d4a679b0",
   "metadata": {},
   "source": [
    "一维数组切分，切4份或数组元素3，5开头各自一份，其余一份"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4c1ff8d7-2a6e-4a42-989e-aceeb40264eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr2=arr1.reshape(2,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8c219239-8ade-41e3-ae03-b0a83dca89e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [ 6,  7,  8,  9, 10, 11]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "856fbd09-2fa8-4bcb-82bd-e8b96fc77c3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[0, 1, 2, 3, 4, 5]]), array([[ 6,  7,  8,  9, 10, 11]])]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.split(arr2,2,axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c48c6152-6f72-4ddb-9a7c-a85f9a2e208d",
   "metadata": {},
   "source": [
    "2维数组横切两份"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4fa3f3c3-5e20-4152-9a28-e4815655eb5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[array([[0, 1, 2],\n",
       "        [6, 7, 8]]),\n",
       " array([[ 3,  4,  5],\n",
       "        [ 9, 10, 11]])]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.split(arr2,2,1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c834cc3-2db4-4349-b64b-679214299062",
   "metadata": {},
   "source": [
    "2维数组竖切两份"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e7e0c602-42d3-4fcd-93dd-5c66e5ef90d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  6],\n",
       "       [ 1,  7],\n",
       "       [ 2,  8],\n",
       "       [ 3,  9],\n",
       "       [ 4, 10],\n",
       "       [ 5, 11]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.transpose(arr2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7614c2b-dcbb-4cf3-9720-ca73ca5b46bf",
   "metadata": {},
   "source": [
    "转置矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f25047a8-c73e-4099-b999-7489c098e6ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr3=np.arange(9).reshape(3,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "7175d590-2703-4467-9c43-8325132965ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "039ea49e-9c15-4881-b46d-a2f07f026995",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr4=np.arange(9).reshape(3,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "4fddb82d-e9b2-4cbc-8b6f-b39a169e6086",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c56cfa0f-fb75-4938-b46a-047cdc7f3e55",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr5=[1,2,3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "e943f6b8-3055-4662-945c-80518805f803",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  3,  5],\n",
       "       [ 4,  6,  8],\n",
       "       [ 7,  9, 11]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr6=arr4+arr5\n",
    "arr6"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f959585e-0366-427c-b516-54eecd602e9c",
   "metadata": {},
   "source": [
    "2维+1维一定情况下可以，将低维补0凑成高维同型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "3cb91de9-6e15-47ce-9864-ce008d2cbe80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  4,  7],\n",
       "       [ 7, 10, 13],\n",
       "       [13, 16, 19]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.add(arr3,arr6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b82929e5-96da-4a5b-bca9-044e44c28af8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1, -2, -3],\n",
       "       [-1, -2, -3],\n",
       "       [-1, -2, -3]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.subtract(arr3,arr6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "eba2c4a0-ed32-48dd-a077-fe00e3960450",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr7=np.arange(9).reshape(3,3)\n",
    "arr8=np.arange(9).reshape(3,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "bfaf470c-e405-4d1e-93b6-a974945cd7cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "2dfd17ab-b563-4f94-b64b-e64dbdf55687",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 1, 2],\n",
       "       [3, 4, 5],\n",
       "       [6, 7, 8]])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "b99d876c-6de3-4e8f-a230-02db5175414a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0.],\n",
       "       [0., 0., 0.],\n",
       "       [0., 0., 0.]])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr9=np.empty(9).reshape(3,3)\n",
    "arr9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "af014a56-32c5-402a-a39b-fc9ed4ac5ad2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.,  1.,  4.],\n",
       "       [ 9., 16., 25.],\n",
       "       [36., 49., 64.]])"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.multiply(arr7,arr8,arr9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "032071a6-b61f-49bb-882f-e80e19081e58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.,  1.,  4.],\n",
       "       [ 9., 16., 25.],\n",
       "       [36., 49., 64.]])"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr9"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "632896c3-1fed-4530-8f1c-a669cddcbea7",
   "metadata": {},
   "source": [
    "只满足扩充或者同型矩阵乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "a4acc119-3ce4-4e22-a4a1-b69f8071e748",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.0)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.floor(4.12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "dbc3e4a0-7bae-42ad-920c-98958e39e763",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(5.0)"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ceil(4.12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "96c9a949-ea1c-4137-8d90-18e1b7deb289",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(4.0)"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.around(4.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6b07365-550b-4acf-b394-042c8c52b903",
   "metadata": {},
   "source": [
    "用floor或celi进行向下/向上取整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "079b45cd-0e67-43ed-b32b-691cbfbd92b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "list=[1,2,3,4,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "e15d5233-d162-4f5f-8655-bdd55e0716bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr10=np.array(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "e1c15621-64bf-4c20-8353-ce5d05a51924",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "9b117d4a-c265-40bd-9175-7f5bbd8209d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(15)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(arr10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "a5235f98-5042-49d0-ad5f-490f121645c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(120)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.prod(arr10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "dd19a2fd-926f-4590-b49e-e56706e7e306",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(3.0)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(arr10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "b6db1b43-c8fa-4027-ad99-fa3c8ca04372",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(1.4142135623730951)"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(arr10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64384e1c-c3e6-432b-a2c2-96e6c4c01e4a",
   "metadata": {},
   "source": [
    "标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "f11466a2-8c9b-4a25-b8a0-2a83a63df739",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(2.0)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.var(arr10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b9c8940-2371-40a6-beed-02c819b06ed4",
   "metadata": {},
   "source": [
    "方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "0bb50752-cb9e-4601-b536-36d9936c1114",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(3.0)"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.median(arr10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6258ec20-dec6-45d1-9e57-f3c51004c62a",
   "metadata": {},
   "source": [
    "中位数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "ef330949-af21-4908-b2e4-e11c1615d5dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  4,  9, 16, 25])"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.power(arr10,2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a396775-ac97-40fc-bb2a-d6268a0fd8c4",
   "metadata": {},
   "source": [
    "平方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "8596c802-dc56-4117-afff-964c4f566f53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.        , 1.41421356, 1.73205081, 2.        , 2.23606798])"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(arr10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6abbc953-ff38-4dca-a40a-28c44b67bca8",
   "metadata": {},
   "source": [
    "开方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "151c7b1d-f09a-4938-a04e-e65f2b26dba6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(5)"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(arr10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "9cc08f8b-2ae2-437f-a3f3-c5f6917badd5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(0)"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.argmin(arr10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79484174-3594-4a31-b225-09c6932d982c",
   "metadata": {},
   "source": [
    "取最小值下标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "ab23b0d4-6495-42ef-babe-5e53e1f17a79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  2.71828183,   7.3890561 ,  20.08553692,  54.59815003,\n",
       "       148.4131591 ])"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.exp(arr10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "422f2292-6ad7-41e2-900b-14f41b84dbf4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.69314718, 1.09861229, 1.38629436, 1.60943791])"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.log(arr10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c195f99b-7bf6-4853-8ab8-c5f8658081a3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
